package fun.liuyu2783.dtc.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import fun.liuyu2783.dtc.common.Response;
import fun.liuyu2783.dtc.order.dao.OrderInfoMapper;
import fun.liuyu2783.dtc.order.dto.OrderInfo;
import fun.liuyu2783.dtc.order.feign.GoodsFeign;
import fun.liuyu2783.dtc.order.service.OrderInfoService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuyu07
 * @since 2021-11-23
 */
@Slf4j
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private GoodsFeign goodsFeign;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Response createOrder(String tradeId){
        log.info("xid={}", RootContext.getXID());
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setId(tradeId);
        super.save(orderInfo);
        goodsFeign.stock(tradeId);
        return Response.success();
    }
}
